package com.xiaoyg.thread;

import java.util.concurrent.*;


/**
 * 1、线程如何保活？
 * 2、线程如何回收？
 * 3、核心线程执行任务抛了异常如何继续？
 * 4、线程添加逻辑，Dubbo中的EagerExecutorPool
 * 5、ctl
 * 6、5种状态
 * 7、shutdown
 *
 * 高3位存储线程池状态
 * 低29位存储线程池线程个数
 *
 * 1<<29 -1 =2的29次方
 * RUNNING:   111 000000000000000000000000000000
 * SHUTDOWN:  000 000000000000000000000000000000
 * STOP:      001 000000000000000000000000000000
 * TIDYING:   010 000000000000000000000000000000
 * TERMINATED 011 000000000000000000000000000000
 *
 * 线程池个数最大位2的29次方
 *
 */
public class ThreadPoolTest {

    public static void main(String[] args) {
        //线程池里面有0个
        ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 200,
                1000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());

        /**
         * 核心：10个
         * 最大：200个
         * 超时：0
         *
         */
        executor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.printf("业务流程。。。。");
                throw new NullPointerException();
            }
        });

        executor.shutdown();
        executor.shutdownNow();

    }

}
